# Author: 空间栈
# Gitee: https://gitee.com/shujianyang/gras-data-processing

import argparse
import re
from pathlib import Path

ap = argparse.ArgumentParser()
ap.add_argument('-i', '--inputdir', required=True,
                help='Input folder where images are stored.')
args = vars(ap.parse_args())

dir_path = args['inputdir']
input = Path(dir_path)
image_name_pattern = r'^(CE|HX).+(?P<timestamp>\d{14}).+\.(jpg|png)$'

for path in input.iterdir():
    m = re.search(image_name_pattern, path.name)
    if m:
        new_filename = f"{m.group('timestamp')}_{path.name}"
        path.rename(input.joinpath(new_filename))
